﻿using System;
using System.Collections.Generic;
using System.Linq;
using SoftSource.Ria;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.Model
{
    public sealed partial class ProjectManagerModel : IModelQueries
    {
        #region Parameter-less
        public IObservable<Unit> LoadData()
        {
            return Observable.Create<Unit>(observer =>
            {
                this.PreLoadQuery.Subscribe(unit =>
                {
                    this.SetResources();
                    observer.OnNext(unit);
                    observer.OnCompleted();
                });

                return () => { };
            });
        }

        public IObservable<IEnumerable<EntryLog>> GetEntriesPriorToLastBillingDate()
        {
            return this.entries.Query(this.entries.GetEntriesPriorToLastBillingDateQuery());
        }
        #endregion Parameter-less

        #region Parametered

        public IObservable<DateTime> GetProjectCreationDate(int projectID)
        {
            return DomainContextExtensions.AsObservable(() => this.utilities.GetProjectCreationDate(projectID))
                .Where(obj => obj is DateTime)
                .Select(obj => (DateTime)obj);
        }

        public IObservable<IEnumerable<EntrySummary>> GetUtilizationSummaries(DateTime startDate, DateTime endDate)
        {
            return this.entries.Query(this.entries.GetUtilizationSummariesQuery(startDate, endDate));
        }

        public IObservable<IEnumerable<EntryLog>> GetFilteredEntries(
            int? projectID,
            int? userID,
            DateTime? startDate,
            DateTime? endDate)
        {
            return this.entries.Query(this.entries.GetFilteredEntryLogsQuery(
                projectID,
                userID,
                startDate,
                endDate));
        }
        #endregion Parametered

        #region Unused
        public IObservable<User> LoadDataForUser(int userID)
        {
            throw new NotImplementedException();
        }

        public IObservable<Project> LoadDataForProject(int projectID)
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<LastEntry>> GetLatestEntries()
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<EntryLog>> GetFlaggedEntries()
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<EntryLog>> GetEntriesPastProjectDueDate()
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<ProjectSummary>> GetProjectsWithInvalidManagers()
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<ProjectMember>> GetProjectMembersForUser(int userID)
        {
            throw new NotImplementedException();
        }

        public IObservable<IEnumerable<EntryLog>> MarkEntriesAsBilled(int projectID, DateTime? startDate, DateTime endDate)
        {
            throw new NotImplementedException();
        }

        public IObservable<Unit> SendReminders(
            string password,
            IEnumerable<int> userIDs,
            string message)
        {
            throw new NotImplementedException();
        }

        public IObservable<Unit> SendEmail(
            string password,
            IEnumerable<int> toUserIDs,
            IEnumerable<int> ccUserIDs,
            string subject,
            string message,
            bool seperateToAddresses)
        {
            throw new NotImplementedException();
        }
        #endregion Unused
    }
}
